/***
 * These unit tests are more like integration tests -
 *  the reason being - it relies on document.cookie and its interface which is very limited
 */
window.storage.cookie.clear();

module("js-simple-storage::cookie");

test("interface contract tests", function() {
    expect(5);
    equals(typeof window.storage.cookie, 'object', 'object exists');
    equals(typeof window.storage.cookie.getItem, 'function', 'function getItem exists');
    equals(typeof window.storage.cookie.setItem, 'function', 'function setItem exists');
    equals(typeof window.storage.cookie.removeItem, 'function', 'function removeItem exists');
    equals(typeof window.storage.cookie.clear, 'function', 'function clear exists');
});

test('getItem', function() {
    // set up a context
    document.cookie = 'a=a; path=/;';
    document.cookie = '1=1; path=/;';
    
    expect(4);
    equals(window.storage.cookie.getItem('a'), 'a', 'getItem(string) returns correct value');
    equals(window.storage.cookie.getItem(1), '1', 'getItem(number) returns correct value');
    equals(window.storage.cookie.getItem(), null, 'getItem() returns null');
    equals(window.storage.cookie.getItem(null), null, 'getItem(null) returns null');
    
    // clean up by removing the cookies
    document.cookie = 'a=; expires= Tue, 06 Jul 2010 10:27:47 GMT; path=/';
    document.cookie = '1=; expires= Tue, 06 Jul 2010 10:27:47 GMT; path=/';
});

test('removeItem', function() {
    // set up a context
    document.cookie = 'a=a; path=/;';
    document.cookie = '1=1; path=/;';
    
    expect(2);
    window.storage.cookie.removeItem('a');
    window.storage.cookie.removeItem(1);
    
    ok(/a/i.test(document.cookie) == false, 'cookie \'a\' removed successfully');
    ok(/1/i.test(document.cookie) == false, 'cookie 1 removed successfully');
});

test("keys", function() {
    expect(1);
    
    // set up
    document.cookie = "utm_source=1; path=/;";
    document.cookie = "utm_action=test; path=/";
    
    ok(window.storage.cookie.keys().length == 2, "correct number of keys returned");
    
    // clean up by removing the cookies
    document.cookie = 'utm_source=; expires= Tue, 06 Jul 2010 10:27:47 GMT; path=/';
    document.cookie = 'utm_action=; expires= Tue, 06 Jul 2010 10:27:47 GMT; path=/';
});